package cn.sdhuijin.healthexam.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import cn.sdhuijin.healthexam.DatabaseHelper;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Constants;

/**
 * 产后随访
 * 
 * @author sunping
 * 
 */
public class ChanHouVisitActivity extends AbstractControlActivity implements
		OnClickListener {

	// 创建日期ID
	private String createDate;
	private DatabaseHelper databaseHelper = new DatabaseHelper(this);

	// 指导
	private int[] zhiDao = { R.id.check_zhidao_grws, R.id.check_zhidao_xinli,
			R.id.check_zhidao_yingyang, R.id.check_zhidao_mrwy,
			R.id.check_zhidao_hlwy };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_chanhou_visit_first);
		ExitApplication.getInstance().addActivity(this);

		Intent intent = getIntent();
		Bundle bundle = intent.getBundleExtra("bundle");
		if (bundle != null) {
			createDate = bundle.getString("createDate");
		}
		setCurrentEditUserName(createDate);

		addEditTextView(R.id.edt_name, "姓名");
		addEditTextView(R.id.edt_identify_num, "身份证号");
		addEditTextView(R.id.edt_tiwen, "体温");
		addEditTextView(R.id.edt_jiankangqingkuang, "一般健康情况");
		addEditTextView(R.id.edt_xinlizhuangkaung, "一般心理状况");
		addEditTextView(R.id.edt_blood_pressure_gao, "高压");
		addEditTextView(R.id.edt_blood_pressure_di, "低压");
		addEditTextView(R.id.edt_qt, "其他");

		addRadioEditUnionView(new int[] { R.id.edt_rufang_ycsm }, "乳房",
				new String[] { "乳房异常" }, R.id.rad_rufang, "异常");
		addRadioEditUnionView(new int[] { R.id.edt_elou_ycsm }, "恶露",
				new String[] { "恶露异常" }, R.id.rad_elou, "异常");
		addRadioEditUnionView(new int[] { R.id.edt_zigong_ycsm }, "子宫",
				new String[] { "子宫异常" }, R.id.rad_zigong, "异常");
		addRadioEditUnionView(new int[] { R.id.edt_shangkou_ycsm }, "伤口",
				new String[] { "伤口异常" }, R.id.rad_shangkou, "异常");
		addRadioEditUnionView(new int[] { R.id.edt_fenlei_ycsm }, "分类",
				new String[] { "分类异常" }, R.id.rad_fenlei, "异常");

		addCheckBoxView(zhiDao, "指导");
		addEditTextView(R.id.edt_zhidao_qt, "其它指导");

		addRadioGroupView(R.id.rad_zhuanzhen, "转诊");
		addEditTextView(R.id.edt_zhuanzhen_yy, "转诊原因");
		addEditTextView(R.id.edt_zhuanzhen_jgjks, "机构及科室");
		addEditTextView(R.id.edt_next_date, "下次随访日期");
		addEditTextView(R.id.edt_visit_doctor, "随访医生签名");
		addEditTextView(R.id.edt_suggestion, "指导意见");

		// // Properties文件路径
		controlManager.setPropertiesPath(Constants.PROPERTIES_PATH + createDate
				+ ".txt");
		Log.i(ChanHouVisitActivity.class.getSimpleName(), "文件路径： "
				+ Constants.PROPERTIES_PATH + createDate + ".txt");
		controlManager.toControl();

		setEditTextListener(R.id.edt_next_date);
		setButtonListener(this, R.id.btn_complete, R.id.btn_back);
	}

	/**
	 * 按钮点击处理事件
	 */
	@Override
	public void onClick(View arg0) {
		Intent intent = new Intent();
		// 获取点击按钮ID
		int id = (Integer) arg0.getId();
		switch (id) {
		case R.id.btn_back:
			this.finish();
			break;
		case R.id.btn_complete:
			controlManager.toProperties();
			databaseHelper.updateIndexTable(createDate);
			this.toastInformation(R.string.toast_submit_info);
			intent.setClass(this, IndexActivity.class);
			startActivity(intent);
			break;
		default:
			break;
		}
	}
}
